$('.old').click(function() {
    var pass_type = $('#old-password').attr('type');

    if (pass_type === 'password') {
        $('#old-password').attr('type', 'text');
        $('.old').removeClass('operate-eye-open').addClass('operate-eye-close');
    } else {
        $('#old-password').attr('type', 'password');
        $('.old').removeClass('operate-eye-close').addClass('operate-eye-open');
    }
});
$('.new-pass').click(function() {
    var pass_type = $('#new-password').attr('type');


    if (pass_type === 'password') {
        $('#new-password').attr('type', 'text');
        $('.new-pass').removeClass('operate-eye-open').addClass('operate-eye-close');
    } else {
        $('#new-password').attr('type', 'password');
        $('.new-pass').removeClass('operate-eye-close').addClass('operate-eye-open');
    }
});

$('.confirm').click(function() {
    var pass_type = $('#confirm').attr('type');

    if (pass_type === 'password') {
        $('#confirm').attr('type', 'text');
        $('.confirm').removeClass('operate-eye-open').addClass('operate-eye-close');
    } else {
        $('#confirm').attr('type', 'password');
        $('.confirm').removeClass('operate-eye-close').addClass('operate-eye-open');
    }
});

//发送验证码
var InterValObj; //timer变量，控制时间
// var count = 60; //间隔函数，1秒执行
var curCount=60; //当前剩余秒数

function SetRemainTime() {
    if (curCount == 0) {
        window.clearInterval(InterValObj);
        //停止计时器
        $("#send-validation").removeAttr("disabled");
        //启用按钮
        $("#send-validation").html("重新获取");
        curCount=60;
    } else {
        curCount--;
        $("#send-validation").html(curCount + "秒");
    }
}
$('#send-validation').on('click', function (e) {

    $("#send-validation").attr("disabled", "true");
    $("#send-validation").html(curCount + "秒");
    InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
    $.post("/sendValidateCode",
        { bizType: "PASS_WORD_MODIFY"},
        function(result) {
            $.alert(result.message)
        })

});


    $('#save_btn').on('click',function(){

        var newPassword=$("input[name='new-password']");
        var confirmPassword=$("input[name='confirm']");

        var newPass=newPassword.val();
        var confirmPass=confirmPassword.val();
        if(newPass!=confirmPass){
            // $.toast("两次输入的新密码不一致，请重新输入！");
            $.alert('两次输入的密码不一致，请重新输入！', function () {

               newPassword.val("");
               confirmPassword.val("");
                newPassword.focus();
            });
            return;
        }
        var validateCode=$("input[name='code']").val();
        var param = {
            "validateCode":validateCode,
            "newPassword": newPass
        };

        $.post("/user_center/account/modify_pwd",param,function(data){
                if(data.code==1){

                    $.alert(data.message);
                    $("input[name='code']").val('');
                    window.location.href="/log_out";
                }else {
                    $.alert(data.message);
                    $("input[name='code']").val('');
                }
            }
        );
    });

